<template>
  <div>
    <!-- form表单 -->
    <el-form :inline="true">
      <el-form-item label="学生状态">
        <el-select placeholder="请选择">
          <el-option label="未使用" value="1"></el-option>
          <el-option label="已使用" value="0"></el-option>
          <el-option label="已过期" value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="优惠券名称">
        <el-input
          v-model="name"
          placeholder="请输入优惠券名称关键字"
        ></el-input>
      </el-form-item>
      <el-button @click="search">搜索</el-button>
      <el-button @click="reset">重置</el-button>
    </el-form>
    <el-table :data="res" border style="width: 100%">
      <el-table-column prop="name" label="优惠券名称" width="300">
      </el-table-column>
      <el-table-column prop="name" label="学员昵称" width="300">
      </el-table-column>
      <el-table-column prop="created_at" label="学员手机号" width="240">
      </el-table-column>
      <el-table-column label="领取日期" width="300">
        <template slot-scope="scope">
          {{ scope.row.created_at | formatDate }}
        </template>
      </el-table-column>
      <el-table-column prop="grant" label="使用状态" width="200">
        <template slot-scope="scope">
          {{ scope.row.grant === 1 ? "启用" : "禁用" }}
        </template>
      </el-table-column>

      <el-table-column label="使用时间" width="300">
        <template slot-scope="scope">
          {{ scope.row.created_at | formatDate }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="Coupon.length"
      :page-sizes="[1, 2, 3]"
      :page-size="pagesize"
      :current-page="pagenum"
      @size-change="sizechange"
      @current-change="pagechange"
    >
    </el-pagination>
  </div>
</template>
<script>
import { getCoupon } from '../../../api'
export default {
  data() {
    return {
      Coupon: [],
      name: '',
      value: '',
      list: [],
      pagesize: 5,
      pagenum: 1
    }
  },
  created() {
    getCoupon().then((res) => {
      if (res) {
        this.Coupon = res.data.list
        this.list = res.data.list
      }
    })
  },
  methods: {
    search() {
      console.log(this.name)
      this.Coupon = this.Coupon.filter((item) => {
        return item.name.includes(this.name)
      })
    },
    reset() {
      this.Coupon = this.list
      this.name = ''
    },
    sizechange(val) {
      console.log(val)
      this.pagesize = val
    },

    pagechange(val) {
      console.log(val)
      this.pagenum = val
    }
  },
  computed: {
    res() {
      return this.Coupon.slice(
        this.pagesize * (this.pagenum - 1),
        this.pagesize * this.pagenum
      )
    }
  }
}
</script>
